<?php

namespace app\api\library;


use Exception;
use think\cache\driver\Redis;

class Sms
{
    public	$user 		= 'xc10223';	//短信账户		默认liyi
    public	$password 	= 'kx0223';	//账户密码
    public	$signature 	= '快学';	//签名
    public function sendPhoneCode($phone,$code,$type)
    {
        $arr = [
            'register' => "【{$this->signature}】您申请的验证码:@,您正在注册成为会员，感谢您的支持！",
            'resetpwd' => "【{$this->signature}】尊敬的用户，您正在申请忘记密码,验证码为:@,请勿泄漏于他人！",
            'changepwd' => "【{$this->signature}】尊敬的用户，您的验证码为:@,请勿泄漏于他人！",
            'changemobile' => "【{$this->signature}】尊敬的用户，您的验证码为:@,请勿泄漏于他人！",
            'bindBankCard' => "【{$this->signature}】尊敬的用户，您的验证码为:@,请勿泄漏于他人！",
        ];

        try {
            $content = str_replace("@",$code,$arr[$type]);
            $codearray['code'] = $code;
            $smsapi = "http://47.92.214.24/smsJson.aspx";
            $pass = md5($this->password);
            $sendurl = $smsapi.'?action=send&userid=&account='.$this->user.'&password='.$pass.'&mobile='.$phone.'&content='.$content.'&sendTime=&extno=';
            $sendurl=urldecode($sendurl);
            $result =file_get_contents($sendurl);
            $result = json_decode($result);
            if ($result->successCounts) {
                return true;
            }
        } catch (\Exception $exception) {
            throw new \Exception($exception->getMessage(),500);
        }
        return false;
    }
}